<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html class="pixel-ratio-2 retina android android-6 android-6-0"><head>
    <title>游戏代理后台</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="${ctx }/templates/default/skins/default/h5/lib/weui.min.css">
    <link rel="stylesheet" href="${ctx }/templates/default/skins/default/h5/css/jquery-weui.css">
    <link rel="stylesheet" href="${ctx }/templates/default/skins/default/h5/css/lehe.css">

<body ontouchstart="">
<heaer>
    <div class="header">
        <a href="javascript:history.go(-1);" class="title">
            <span class="header-icon4"></span>
        </a>
        <span class="title-txt J-title-txt">代理购币</span>
    </div>
    <div class="header-secondary"></div>
</heaer>

<div class="weui-cells weui-cells_form" style="margin-top: 5px;">
    <input id="wxOpenId" type="hidden" value="${sessionScope.session_user_key.wxOpenId}" />
    <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
        <div class="weui-media-box__hd">
            <img class="weui-media-box__thumb" src="${userInfo.userImg}" alt="">
        </div>
        <div class="weui-media-box__bd">
            <h4 class="weui-media-box__title">UID:${userInfo.userId}</h4>
            <p class="weui-media-box__desc">本人剩余金币:${userInfo.goldCoinCount}</p>
        </div>
    </a>

    <div class="weui-cells">
        <div class="weui-cell weui-cell_select weui-cell_select-after">
            <div class="weui-cell__hd">
                <label for="" class="weui-label">选择数量</label>
            </div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="goldLv" id="goldLv">
                    <option value="lv8">200元6000金币</option>
                    <%--<option value="lv1">500元18750金币</option>--%>
                    <option value="lv7">500元20000金币</option>
                    <option value="lv2">1000元42000金币</option>
                    <option value="lv3">2000元90000金币</option>
                    <option value="lv4">5000元249000金币</option>
                    <option value="lv5">10000元540000金币</option>
                    <option value="lv6">30000元2235000金币</option>
                </select>
            </div>
        </div>
    </div>

</div>

<div class="lehe-content-padded">
    <a id="confirm_pay" class="weui-btn weui-btn_primary">确认支付</a>
</div>

<script src="${ctx }/templates/default/skins/default/h5/lib/jquery-2.1.4.js"></script>
<script src="${ctx }/templates/default/skins/default/h5/js/jquery-weui.js"></script>


<script>
    /*function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId":"wx2421b1c4370ec43b",     //公众号名称，由商户传入
                "timeStamp":"1395712654",         //时间戳，自1970年以来的秒数
                "nonceStr":"e61463f8efa94090b1f366cccfbbb444", //随机串
                "package":"prepay_id=u802345jgfjsdfgsdg888",
                "signType":"MD5",         //微信签名方式：
                "paySign":"70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名
            },
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {}     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
            }
        );
    }
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }*/

    $(document).on("click", "#confirm_pay", function() {
    	var wxOpenId = $("#wxOpenId").val();
        var goldLv = $("#goldLv").val();
        $.showLoading();
        $.post('../agent/confirmPay',{wxOpenId:wxOpenId, goldLv:goldLv},function(result){
            $.hideLoading();
            if(result && result.code=="1") {
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', {
                        "appId":result.appId,     //公众号名称，由商户传入
                        "timeStamp":result.timeStamp,         //时间戳，自1970年以来的秒数
                        "nonceStr":result.nonceStr, //随机串
                        "package":result.package,
                        "signType":result.signType,         //微信签名方式：
                        "paySign":result.paySign //微信签名
                    },
                    function(res){
                        console.log(res);
                        if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                            $.toast("支付成功", "text");
                            // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                        }else {
                            $.toast("支付失败", "forbidden");
                        }
                    }
                );
            }else {
                $.toast("支付失败", "forbidden");
            }
        }, 'json');
    });

</script>

</body>
</html>